<template>
  <!-- 编辑弹出框 -->
  <el-dialog title="编辑" :visible.sync="visible" @close="$emit('close')" width="60%">
    <el-form ref="form" :model="form" label-width="70px">
      <el-form-item label="Logo">
         <img style="width:35px;" :src="'/upload/'+ form.companyLogo"  alt=""> &nbsp;
        <el-upload action="https://jsonplaceholder.typicode.com/posts/" :on-preview="handlePreview" :on-remove="handleRemove" :before-remove="beforeRemove" :before-upload="beforeUpload" :on-exceed="handleExceed" :file-list="fileList">
         
          <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
          
          <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
        </el-upload>
      </el-form-item>
      <el-form-item label="公司名称">
        <el-input v-model="form.companyName"></el-input>
      </el-form-item>
      <el-form-item label="城市">
        <el-select v-model="form.city" placeholder="请选择">
          <el-option-group v-for="group in options" :key="group.label" :label="group.label">
            <el-option v-for="item in group.options" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-option-group>
        </el-select>
      </el-form-item>
      <el-form-item label="职位名称">
        <el-input v-model="form.positionName" maxlength="15"></el-input>
      </el-form-item>
      <el-form-item label="薪水">
        <el-input v-model="form.salary" maxlength="15"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="$emit('close')">取 消</el-button>
      <el-button type="primary" @click="saveEdit">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { update } from "../../api/position"

export default {
  props: ["visible", "items"],
  created() {
    this.form = Object.assign(this.form, this.items)
  },
  data() {
    return {
      fileList: [],
      form: {
        companyLogo: {}
      },
      options: [
        {
          label: "热门城市",
          options: [
            {
              value: "Shanghai",
              label: "上海"
            },
            {
              value: "Beijing",
              label: "北京"
            }
          ]
        },
        {
          label: "城市名",
          options: [
            {
              value: "Chengdu",
              label: "成都"
            },
            {
              value: "Shenzhen",
              label: "深圳"
            },
            {
              value: "Guangzhou",
              label: "广州"
            },
            {
              value: "Dalian",
              label: "大连"
            }
          ]
        }
      ],
      value: ""
    }
  },
  methods: {
    beforeUpload(file) {
      this.form.companyLogo = file;
    },
    handlePreview() {},
    handleRemove() {},
    beforeRemove() {},
    handleExceed() {},
    saveEdit() {
      this.$refs.form.validate(async valid => {
        if (valid) {
          this.fd = new FormData()
          for (let key in this.form) {
            this.fd.append(key, this.form[key])
          }
          let rs = await update(this.fd)
          if (rs.code === 1) {
            this.$message({
              showClose: true,
              type: "success",
              message: "更新成功"
            })
          }else{
             this.$message({
              showClose: true,
              type: "warning",
              message: "更新失败"
            })
          }
        }
      })
    }
  }
}
</script>
<style lang="scss">
.el-upload--text {
  border: none;
  width: auto;
  height: auto;
}
</style>


